package com.tbit.uqbike.webmanager.controller;

import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.object.pojo.InvoiceConfig;
import com.tbit.uqbike.service.business.InvoiceConfigService;
import com.tbit.uqbike.webmanager.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 发票配置
 * @author: mo.shanyong
 * @date: 2025/4/2 11:17
 */
@RestController
@RequestMapping("/invoiceConfig")
public class InvoiceConfigController extends BaseController {

    @Autowired
    private InvoiceConfigService invoiceConfigService;

    /**
     * @description: 增加或修改发票配置
     * @author: mo.shanyong
     * @date: 2025/4/2 11:16
     * @param: invoiceConfig
     * @return: com.tbit.common.entity.view.Result
     */
    @PostMapping("/addOrEdit")
    public Result<Object> addOrEditInvoiceConfig(@RequestBody InvoiceConfig invoiceConfig){
        Assert.notNull(invoiceConfig.getBrandId(),"品牌id不能为空");
        Assert.notNull(invoiceConfig.getAppId(),"AppID不能为空");
        Assert.notNull(invoiceConfig.getAppSecret(),"AppSecret不能为空");
        Assert.notNull(invoiceConfig.getNotifyUrl(),"回调url不能为空");
        Assert.notNull(invoiceConfig.getRequestHost(),"请求域名不能为空");
        Assert.notNull(invoiceConfig.getGetTokenUrl(),"验签url不能为空");
        invoiceConfigService.addOrEdit(invoiceConfig);
        return Result.success();
    }

    /**
     * @description: 根据品牌id获取发票配置
     * @author: mo.shanyong
     * @date: 2025/4/2 11:29
     * @param: brandId 品牌id
     * @return: com.tbit.common.entity.view.Result<com.tbit.uqbike.object.pojo.InvoiceConfig>
     */
    @GetMapping("/getByBrandId")
    public Result<InvoiceConfig> getByBrandId(@RequestParam Integer brandId){
        InvoiceConfig invoiceConfig = invoiceConfigService.queryByBrandId(brandId);
        return Result.success(invoiceConfig);
    }
}
